angular.module('mamApp').controller('transcodingProgramsController', ['$scope', 'TranscodingManager', '$state', '$uibModal', 'ChannelManager',
    function ($scope, TranscodingManager, $state, $uibModal, ChannelManager) {
        $scope.transcodingStatus = [{key: "", value: "转码状态"}, {key: 90, value: $scope.table[90]}, {
            key: 91,
            value: $scope.table[91]
        }, {
            key: 92,
            value: $scope.table[92]
        }];


        $scope.fileNames = [{key: "", value: "查找字段"}, {key: "programId", value: "节目ID"}, {
            key: "programName",
            value: "节目名称"
        }];
        $scope.albumId = $state.params.albumId;
        $scope.albumName = $state.params.albumName;


        $scope.search = {
            pageNo: $state.params.pageNo || 1,
            pageSize: $state.params.pageSize || 10,
            convertStatus: $state.params.convertStatus ? parseInt($state.params.convertStatus) : "",
            key: $state.params.key || "",
            value: $state.params.value || ""
        };


        $scope.findData = function () {
            $scope.search.pageNo=1;
            $state.go($state.current.name, $scope.search);
        }


        $scope.channels = [{channelId: "", channelName: "二级频道"}];


        $scope.convertStatusChange = function () {
            $scope.search.pageNo=1;
            $state.go($state.current.name, $scope.search);

        }


        $scope.paginationConf = {
            currentPage: $state.params.pageNo || 1,
            itemsPerPage: $state.params.pageSize || 10,
            pagesLength: 9,
            search: 0,
            onChange: function () {
                $scope.search.pageNo = this.currentPage;
                $scope.search.pageSize = this.itemsPerPage;
                $state.go($state.current.name, $scope.search)
            }
        }


        TranscodingManager.transcodingPrograms($scope.albumId, [$scope.search.pageNo, $scope.search.pageSize], $scope.search).then(function (result) {
            $scope.programs = result.data.pageList;
            $scope.paginationConf.totalItems = result.data.total;
        })

        $scope.keyup=function (e,keyword) {

            if(e.key=="Enter"){
                $scope.search.pageNo=1;
                $scope.search.keyword = keyword;
                $scope.search.reviewStatus = $scope.search.reviewStatus == "null" ? null : $scope.search.reviewStatus;
                $state.go($state.current.name, $scope.search)
            }
        }


    }])

